﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GUI
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
            XuLyDangNhap();
        }

        private String _tenUser;
        private int _maUser;
        private int _bophanUser;

        private void hóaĐơnNhậpMuaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            frmHoaDonBanVe fr = new frmHoaDonBanVe();
            fr.TopLevel = false;
            fr.Dock = DockStyle.Fill;
            fr.Visible = true;
            panel1.Controls.Add(fr);
        }

        private void hóaĐơnXuấtBánToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            frmHoaDonSanPham fr = new frmHoaDonSanPham();
            fr.TopLevel = false;
            fr.Dock = DockStyle.Fill;
            fr.Visible = true;
            panel1.Controls.Add(fr);
        }

        private void đơnĐặtHàngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            frmDonDatHangNVL fr = new frmDonDatHangNVL();
            fr.TopLevel = false;
            fr.Dock = DockStyle.Fill;
            fr.Visible = true;
            panel1.Controls.Add(fr);
        }

        private void phiếuNhậpKhoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            frmPhieuNhapKho fr = new frmPhieuNhapKho();
            fr.TopLevel = false;
            fr.Dock = DockStyle.Fill;
            fr.Visible = true;
            panel1.Controls.Add(fr);
        }

        private void phiếuXuấtKhoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            frmPhieuXuatKho fr = new frmPhieuXuatKho();
            fr.TopLevel = false;
            fr.Dock = DockStyle.Fill;
            fr.Visible = true;
            panel1.Controls.Add(fr);
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            frmPhanCong fr = new frmPhanCong();
            fr.TopLevel = false;
            fr.Dock = DockStyle.Fill;
            fr.Visible = true;
            panel1.Controls.Add(fr);
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            lbHomNay.Text = "Hôm nay: " + DateTime.Today.ToString("dd/MM/yyyy");
        }

        public void BoPhanKho()
        {
            tsHoaDonBanVe.Enabled = false;
            tsHoaDonSanPham.Enabled = false;
            this.tsDonDatHangNVL.Enabled = false;
            this.tsPhieuNhapKho.Enabled = true;
            this.tsPhieuXuatKho.Enabled = true;
            this.tsPhanCongNhanVien.Enabled = false;

            menuHoaDonBanVe.Enabled = false;
            this.menuHoaDonSanPham.Enabled = false;
            this.menuDonDatHangNVL.Enabled = false;
            this.menuPhieuNhapKho.Enabled = true;
            this.menuPhieuXuatKho.Enabled = true;
            this.menuPhanCongNhanVien.Enabled = false;
        }
        public void BoPhanBep()
        {
            tsHoaDonBanVe.Enabled = false;
            tsHoaDonSanPham.Enabled = false;
            this.tsDonDatHangNVL.Enabled = true;
            this.tsPhieuNhapKho.Enabled = false;
            this.tsPhieuXuatKho.Enabled = false;
            this.tsPhanCongNhanVien.Enabled = false;

            menuHoaDonBanVe.Enabled = false;
            this.menuHoaDonSanPham.Enabled = false;
            this.menuDonDatHangNVL.Enabled = true;
            this.menuPhieuNhapKho.Enabled = false;
            this.menuPhieuXuatKho.Enabled = false;
            this.menuPhanCongNhanVien.Enabled = false;
        }
        public void BoPhanThuNgan()
        {
            tsHoaDonBanVe.Enabled = true;
            tsHoaDonSanPham.Enabled = true;
            this.tsDonDatHangNVL.Enabled = false;
            this.tsPhieuNhapKho.Enabled = false;
            this.tsPhieuXuatKho.Enabled = false;
            this.tsPhanCongNhanVien.Enabled = false;

            menuHoaDonBanVe.Enabled = true;
            this.menuHoaDonSanPham.Enabled = true;
            this.menuDonDatHangNVL.Enabled = false;
            this.menuPhieuNhapKho.Enabled = false;
            this.menuPhieuXuatKho.Enabled = false;
            this.menuPhanCongNhanVien.Enabled = false;
        }
        public void BoPhanQuanLy()
        {
            tsHoaDonBanVe.Enabled = false;
            tsHoaDonSanPham.Enabled = false;
            this.tsDonDatHangNVL.Enabled = false;
            this.tsPhieuNhapKho.Enabled = false;
            this.tsPhieuXuatKho.Enabled = false;
            this.tsPhanCongNhanVien.Enabled = true;

            menuHoaDonBanVe.Enabled = false;
            this.menuHoaDonSanPham.Enabled = false;
            this.menuDonDatHangNVL.Enabled = false;
            this.menuPhieuNhapKho.Enabled = false;
            this.menuPhieuXuatKho.Enabled = false;
            this.menuPhanCongNhanVien.Enabled = true;
        }

        public void Admin()
        {
            tsHoaDonBanVe.Enabled = true;
            tsHoaDonSanPham.Enabled = true;
            this.tsDonDatHangNVL.Enabled = true;
            this.tsPhieuNhapKho.Enabled = true;
            this.tsPhieuXuatKho.Enabled = true;
            this.tsPhanCongNhanVien.Enabled = true;

            menuHoaDonBanVe.Enabled = true;
            this.menuHoaDonSanPham.Enabled = true;
            this.menuDonDatHangNVL.Enabled = true;
            this.menuPhieuNhapKho.Enabled = true;
            this.menuPhieuXuatKho.Enabled = true;
            this.menuPhanCongNhanVien.Enabled = true;
        }
        public void XuLyDangNhap()
        {
            _tenUser = frmDangNhap.Ten;
            _maUser = frmDangNhap.Ma;
            _bophanUser = frmDangNhap.BoPhan;
            //if (result == DialogResult.OK)
            //{
                switch (_bophanUser)
                {
                    case 1: Admin();
                        break;
                    case 2: BoPhanQuanLy();
                        break;
                    case 3: BoPhanBep();
                        break;
                    case 4: BoPhanThuNgan();
                        break;
                    case 5: BoPhanKho();
                        break;
                }
                this.lbNguoiDung.Text = "Người dùng: " + _tenUser;

            //}
        }

        private void tsHoaDonBanVe_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            frmHoaDonBanVe fr = new frmHoaDonBanVe();
            fr.TopLevel = false;
            fr.Dock = DockStyle.Fill;
            fr.Visible = true;
            panel1.Controls.Add(fr);
        }

        private void tsHoaDonSanPham_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            frmHoaDonSanPham fr = new frmHoaDonSanPham();
            fr.TopLevel = false;
            fr.Dock = DockStyle.Fill;
            fr.Visible = true;
            panel1.Controls.Add(fr);
        }

        private void tsDonDatHangNVL_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            frmDonDatHangNVL fr = new frmDonDatHangNVL();
            fr.TopLevel = false;
            fr.Dock = DockStyle.Fill;
            fr.Visible = true;
            panel1.Controls.Add(fr);
        }

        private void tsPhieuNhapKho_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            frmPhieuNhapKho fr = new frmPhieuNhapKho();
            fr.TopLevel = false;
            fr.Dock = DockStyle.Fill;
            fr.Visible = true;
            panel1.Controls.Add(fr);
        }

        private void tsPhieuXuatKho_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            frmPhieuXuatKho fr = new frmPhieuXuatKho();
            fr.TopLevel = false;
            fr.Dock = DockStyle.Fill;
            fr.Visible = true;
            panel1.Controls.Add(fr);
        }

        private void tsPhanCongNhanVien_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            frmPhanCong fr = new frmPhanCong();
            fr.TopLevel = false;
            fr.Dock = DockStyle.Fill;
            fr.Visible = true;
            panel1.Controls.Add(fr);
        }

        private void thayĐổiMậtKhẩuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmThayDoiMatKhau frm = new frmThayDoiMatKhau();
            frm.ShowDialog();
        }

        private void đăngNhậpLạiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
            frmDangNhap frm = new frmDangNhap();
            frm.Show();
        }
    }
}
